import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;
import java.util.Random;

public class shu {

    public static void main(String[] args) {
        Properties properties=new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"niit01:9092");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        while(true) {
            int i=0;
            KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
            int classname = new Random().nextInt(8) ;
            //随机产生姓名
            int leftLimit = 97; // letter 'a'
            int rightLimit = 122; // letter 'z'
            int targetStringLength = 5;
            Random random = new Random();
            StringBuilder buffer = new StringBuilder(targetStringLength);
            for (int i1 = 0; i1 < targetStringLength; i1++) {
                int randomLimitedInt = leftLimit + (int)
                        (random.nextFloat() * (rightLimit - leftLimit + 1));
                buffer.append((char) randomLimitedInt);
            }
            String generatedString = buffer.toString();
            int sex = new Random().nextInt(2);
            int ran1=new Random().nextInt(5);
            int[] dt=new int[]{20211203,20210315,20200214,20150124,20160516,20180825};
            int date=dt[ran1];
            int id = new Random().nextInt(999999999) + (1000000000);
            int term =new Random().nextInt(8) + 1;
            int jidian = new Random().nextInt(10)+1;
            String[] categoryArray = new String[]{"A", "L"};
            int ran = new Random().nextInt(2);
            String school = categoryArray[ran];


            String sexSum=Integer.toString(sex);
            String ad1=sex+school;
            String ad2=Integer.toString(term);
            producer.send(new ProducerRecord<String, String>("sou2",sexSum ));
            producer.send(new ProducerRecord<String, String>("sou3",ad2 ));
            producer.send(new ProducerRecord<String, String>("sou4",ad1 ));

            String stu[] = new String[100];
            stu[i]=classname+"\t"+generatedString+"\t"+sex+"\t"+date+"\t"+id+"\t"+term+"\t"+jidian+"\t"+school;
            producer.send(new ProducerRecord<String, String>("stuInfo", stu[i]));
            System.out.println(classname+"\t"+generatedString+"\t"+sex+"\t"+date+"\t"+id+"\t"+term+"\t"+jidian+"\t"+school);

            producer.close();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            i++;

        }
    }
}